#ifndef _physics_h_included_
#define _physics_h_included_
#include <d3dx9.h>
#include <d3d9.h>
#include <string>
#include <Vector>
#include "Model.h"

using namespace std;
class Model;
#define DEGTORAD(x) (x*D3DX_PI/180.0f)

//This class is responsible for maintaining the state
//of a model
class Physics
{
public:
		enum Type{
		Sphere,
		Plane
	};
protected:

	//The model the physics object will update. 
	Model* mModel;
	D3DXVECTOR3* mLinearForce; //The rot of the model
	D3DXVECTOR3* mAngularForce;
	D3DXVECTOR3* mDisplacement;
	D3DXVECTOR3* mVelocity;
	D3DXVECTOR3* mMomentum;
	D3DXVECTOR3* mAccel;

	Type mType;
	float mMass;
	float mRadius;
	float mInertia;
	bool mMoveable;



public:
	//Default Constructor sets everything to zero
	Physics()
	{
		mLinearForce = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mAngularForce = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mDisplacement = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mMass = 1.0f;
		mRadius = 0.0f;
		mInertia = 1.0f;
		mMoveable = true;
		mVelocity = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mMomentum = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mAccel = new D3DXVECTOR3(0.0f,0.0f,0.0f);
	}

	Physics(D3DXVECTOR3* pLinear, D3DXVECTOR3* pAngular, bool pMoveable )
	{
		mLinearForce = pLinear;mAngularForce = pAngular; mMoveable = pMoveable;
		mDisplacement = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mVelocity = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mMomentum = new D3DXVECTOR3(0.0f,0.0f,0.0f);
		mAccel = new D3DXVECTOR3(0.0f,0.0f,0.0f);
	}

	virtual void ApplyForces(D3DXVECTOR3* pLinear, D3DXVECTOR3* pAngular );
	void Update(double pElapsedTime);
	void Finalize(double pElapsedTime);

	void CalcVelocity(double pElapsedTime);
	void CalcDisplacement(double pElapsedTime);
	void CalcMomentum(double pElapsedTime);
	void CalcAcceleration();

	D3DXVECTOR3* GetLinearForce(); //The rot of the model
	D3DXVECTOR3* GetDisplacement();
	D3DXVECTOR3* GetVelocity(){return mVelocity;}
	void SetVelocity(D3DXVECTOR3* pVelocity){mVelocity = pVelocity;}
	D3DXVECTOR3* GetMomentum(){return mMomentum;}
	D3DXVECTOR3* GetAcceleration(){return mAccel;}
	void SetAcceleration(D3DXVECTOR3* pAccel){mAccel = pAccel;}
	float GetMass();
	bool GetMoveable();
	float GetRadius(){return mRadius;}
	float GetInteria(){return mInertia;}
	Type GetType(){return mType;}

	void SetModel(Model* m){mModel = m;}
	void SetType(Type pType){mType = pType;}
	void SetMass(float pMass){mMass = pMass;}
	void SetMoveable(bool pMove){mMoveable = pMove;}
	void SetRadius(float pRadius){mRadius = pRadius;}
	void SetInteria(float pInertia){mInertia = pInertia;}

	virtual void Release();

	void AddAnimation(Animation* pAnim);
};
#endif